home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / SIGNALS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-02  |  2.2 KB  |  93 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <MINTBIND.H>
  9. #include <OSBIND.H>
  10. #include <SIGNAL.H>
  11. #include <VDI.H>
  12. #include "c_window.h"
  13. #include "k_defs.h"
  14. #include "xa_types.h"
  15. #include "xa_globl.h"
  16. #include "xa_defs.h"
  17. #include "xa_codes.h"
  18. #include "new_clnt.h"
  19. #include "signals.h"
  20. #include "messages.h"
  21.  
  22. /*
  23.     SIGNAL HANDLERS
  24. */
  25.  
  26. #define WIFSTOPPED(x)    (((int)((x)&0xff)==0x7f)&&((int)(((x)>>8)&0xff)!=0))
  27. #define WSTOPSIG(x)        ((int)(((x)>>8)&0xff))
  28.  
  29. extern AESPB dead_client_pb;
  30. extern short dead_exit_contrl[];
  31.  
  32. /*
  33.     Spot dead children
  34. */
  35. void __saveds HandleSIGCHLD(long signo)
  36. {
  37.     K_CMD_PACKET dead_client_packet;
  38.     long r;
  39.     short pid;
  40.     XA_CLIENT *client,*parent;
  41.     
  42.     r=Pwait3(1,NULL);
  43.     while(r)
  44.     {
  45.         pid=(r>>16)&0xffff;
  46.         client=Pid2Client(pid);
  47.         
  48.         if (client->clnt_pipe_rd)
  49.         {
  50.  
  51.             dead_client_pb.contrl=dead_exit_contrl;    /* If client is dead, send ourselves a message to clean up.... */
  52.             dead_client_packet.pid=pid;                /* client pid */
  53.             dead_client_packet.cmd=AESCMD_NOREPLY;    /* no reply */
  54.             dead_client_packet.pb=&dead_client_pb;    /* pointer to AES parameter block */
  55.             XA_client_exit(pid,&dead_client_pb);    /* Run the application exit cleanup 
  56.                                                     -gone back to calling directly, as the global command pipe has gone away */
  57.  
  58.             Fclose(client->clnt_pipe_wr);            /* Close the kernal end of client reply pipe */
  59.             client_handle_mask&=~(1L<<client->clnt_pipe_wr);
  60.  
  61.             client->clnt_pipe_wr=client->clnt_pipe_rd=0;
  62.         }
  63.  
  64.         if (client->parent!=AESpid)                    /* Send a CH_EXIT message if the client */
  65.         {                                            /* is not an AES child of the XaAES system */
  66.             unsigned long retv=XA_OK;
  67.  
  68.             DIAGS(("sending CH_EXIT\n"));
  69.  
  70.             parent=Pid2Client(client->parent);
  71.             if (parent->waiting_for&XAWAIT_CHILD)    /* Wake up the parent if it's waiting */
  72.             {
  73.                 Fwrite(parent->clnt_pipe_wr, (long)sizeof(unsigned long),&retv);
  74.             }
  75.             
  76.             send_app_message(client->parent, CH_EXIT, AESpid, pid, r&0xFFFFL, 0, 0, 0);
  77.         
  78.             client->parent=AESpid;
  79.             
  80.         }
  81.         
  82.         r=Pwait3(1,NULL);
  83.     }
  84. }
  85.  
  86. /*
  87.     Catch CTRL+C and exit gracefully from the kernal loop
  88. */
  89. void __saveds HandleSIGINT(long signo)
  90. {
  91.     shutdown=TRUE;
  92. }
  93.